import os
import sys
import time
from modload import load_module
src_path = "../src/"
ConsoleViewer = load_module("ConsoleViewer", src_path)
ConsoleController = load_module("ConsoleController", src_path)
Game = load_module("Game", src_path)
GameManager = load_module("GameManager", src_path)
Player = load_module("Player", src_path)
Team = load_module("Team", src_path)
Stone = load_module("Stone", src_path)

class TestCases:

    def __init__(self):
        self.run_all_tests()

    def run_all_tests(self):
        self.ut_game()
        t = 0
        while t < 1000:
            t = t + 1
        self.ut_gm()
        #self.ut_cc()
        self.ut_cv()
        self.ut_player()
        self.ut_team()
        self.ut_stone()
        

    def ut_cc(self):
        gm = GameManager.GameManager()
        cv = ConsoleViewer.ConsoleViewer()
        myout_p, myin_p = os.pipe()
        myout = os.fdopen(myout_p)
        myin = os.fdopen(myin_p, 'w')

        for test in os.listdir("input"):
            sys.stdout.write("    Testing case "+test+"... ")
            sys.stdout.flush

            # Loop through commands from the input file
            if os.path.isdir("input/"+test):
                continue

            for input in file("input/"+test):
                myin.write(input)

            cc = ConsoleController.ConsoleController(gm, cv, myin, myout)
            cc.run()


    def ut_game(self):
        return

    def ut_cv(self):
        cv = ConsoleViewer.ConsoleViewer()
        cv.print_info("Test: ConsoleViewer\n")
        team = Team.Team(1, "LAG KAMP!")
        player = Player.Player("Hedvig", 2, "right")
        team.add_player(1, player)
        x = 0
        while x < 100:
            #cv.print_team_info(team)
            x = x + 1

    def ut_player(self):
        return
    
    def ut_team(self):
        time.sleep(1)
        return

    def ut_stone(self):
        return

    def ut_gm(self):
        gm = GameManager.GameManager()
        return

if __name__ == "__main__":
    TestCases = TestCases()
